package com.zzyl.controller;

import com.sun.net.httpserver.Authenticator;
import com.zzyl.base.PageResponse;
import com.zzyl.base.ResponseResult;
import com.zzyl.dto.NursingProjectDto;
import com.zzyl.service.NursingProjectService;
import com.zzyl.vo.NursingProjectVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.AutoConfiguration;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@Api(tags = "护理项目")
@RequestMapping("/nursing_project")
@Slf4j
public class NursingProjectController {
    @Autowired
    private NursingProjectService nursingProjectService;
    @GetMapping
    @ApiOperation(value = "分页查询护理项目")
    public ResponseResult<PageResponse<NursingProjectVo>> getByPage(
            @ApiParam(value = "护理项目名称")
            @RequestParam(value = "name", required = false) String name,
            @ApiParam(value = "状态：0-禁用，1-启用")
            @RequestParam(value = "status", required = false) Integer status,
            @ApiParam(value = "当前页码")
            @RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum,
            @ApiParam(value = "每页显示数量")
            @RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize) {
        PageResponse<NursingProjectVo> nursingProjectPageInfo = nursingProjectService.getByPage(name, status, pageNum, pageSize);
        return ResponseResult.success(nursingProjectPageInfo);
    }

    @ApiOperation("新增护理项目")
    @PostMapping
    public ResponseResult addNursingProject(@RequestBody NursingProjectDto nursingProjectDto) {
        log.info("新增护理项目：{}", nursingProjectDto);
        nursingProjectService.addNursingProject(nursingProjectDto);
        return ResponseResult.success();
    }

    @ApiOperation("删除护理项目")
    @DeleteMapping("/{id}")
    public ResponseResult deleteNursingProjectById(@PathVariable Long id) {
        log.info("删除护理项目：{}", id);
        nursingProjectService.deleteNursingProjectById(id);
        return ResponseResult.success();
    }

    @ApiOperation("查询护理项目根据id")
    @GetMapping("/{id}")
    public ResponseResult getNursingProjectById(@PathVariable Long id) {
        log.info("查询护理项目：{}", id);
        NursingProjectVo nursingProject = nursingProjectService.getNursingProjectById(id);
        return ResponseResult.success(nursingProject);
    }

    @PutMapping
    @ApiOperation("修改护理项目")
    public ResponseResult update(@RequestBody NursingProjectDto nursingProjectDTO) {
        nursingProjectService.updateNursingProject(nursingProjectDTO);
        return ResponseResult.success();
    }

    @ApiOperation("修改护理项目状态")
    @PutMapping("/{id}/status/{status}")
    public ResponseResult status(@PathVariable Long id, @PathVariable Integer status) {
        nursingProjectService.enableOrDisable(id, status);
        return ResponseResult.success();
    }

    @ApiOperation(" 查询所有护理项目")
    @GetMapping("/all")
    public ResponseResult getAll() {
        List<NursingProjectVo> list =nursingProjectService.getAll();
        return ResponseResult.success(list);
    }
}
